#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct Tree
{
    int content;
    struct Tree *left;
    struct Tree *right;
};
typedef struct Tree* BT;
void check_tree(BT T)//中序遍历,递归调用
{
    if(T!=NULL)
    {
        check_tree(T->left);
        printf("%d ",T->content);
        check_tree(T->right);
    }
}

BT add_leaf(int input,BT root)//递归加入新元素
{
    if(root==NULL)
    {
        root=(BT)malloc(sizeof(struct Tree));
        root->content=input;
        root->left=NULL;
        root->right=NULL;
    }
    else 
    {
        if(input<root->content) root->left=add_leaf(input,root->left);
        else root->right=add_leaf(input,root->right);
    }
    return root;
}

int main()
{
    char line[1024];
    while(gets(line)!=NULL)
    {
        int temp=0,j;
        BT head=NULL;
        for(j=0;j!=strlen(line);++j)
        {
            if(line[j]>='0'&&line[j]<='9')
            {
                temp=temp*10+(line[j]-'0');
            }
            else
            {
                head=add_leaf(temp,head);
                temp=0;
            }
        }
        if(line[j-1]>='0'&&line[j-1]<='9')
        {
            head=add_leaf(temp,head);
            temp=0;
        }
        check_tree(head);
        printf("\n");
    }
    system("pause");
    return 0;
}